package GUI.Report;

import java.awt.Color;
import java.awt.ComponentOrientation;
import java.awt.Font;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;

import Control.Sys;
import Entity.StatisticsbyAgeAndBirth;
import GUI.Course.CourseManage;
import GUI.Dog.DogManage;
import GUI.Test.TestManage;

import javax.swing.JComboBox;

import org.apache.commons.math3.geometry.Vector;

/**
 * This window display to the user statistical report and data
 * about Dogs (belonging to specific Birth)  performance in various of tests.
 * this class have getters to some of its members.
 * this class also contains input validity checks such: Birth number can be contain only digits.
 * **All communication with the Database is thru Controller Sys.java** 
 */

public class StatisticsReportByBirth extends  JFrame
{
	private static final long serialVersionUID = 1L;
	int f=0;
	JComboBox comboBox=null;
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public StatisticsReportByBirth() throws SQLException, Exception {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setSize(600, 500);
		setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
		setTitle("\u05D3\u05D5\u05D7\u05D5\u05EA \u05E1\u05D8\u05D8\u05D9\u05D9\u05E1\u05D8\u05D9\u05DD");
		getContentPane().setLayout(null);
		
		JButton button_2 = new JButton("\u05E7\u05D5\u05E8\u05E1\u05D9\u05DD");
		button_2.setFont(new Font("David", Font.PLAIN, 14));
		button_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				setVisible(false);
				CourseManage coursewindow=new CourseManage();
				coursewindow.setVisible(true);
				
				
				
			}
		});
		button_2.setBounds(431, 178, 111, 23);
		getContentPane().add(button_2);
		
		JButton button_1 = new JButton("\u05DE\u05D1\u05D7\u05E0\u05D9\u05DD");
		button_1.setFont(new Font("David", Font.PLAIN, 14));
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				setVisible(false);
				TestManage testwindow=new TestManage();
				testwindow.setVisible(true);
				
			}
		});
		button_1.setBounds(431, 292, 111, 23);
		getContentPane().add(button_1);
		
		
		
		
		JButton button = new JButton("\u05D3\u05D5\u05D7\u05D5\u05EA");
		button.setFont(new Font("David", Font.BOLD, 18));
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				setVisible(false);
				ReportManage reportwindow=new ReportManage();
				reportwindow.setVisible(true);
			}
		});
		button.setBounds(431, 236, 111, 23);
		getContentPane().add(button);
		
		JButton btnNewButton = new JButton("\u05DE\u05D0\u05D2\u05E8 \u05DB\u05DC\u05D1\u05D9\u05DD");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				setVisible(false);
				DogManage dogwindow=new DogManage();
				dogwindow.setVisible(true);
			}
		});
		btnNewButton.setFont(new Font("David", Font.PLAIN, 14));
		btnNewButton.setBounds(431, 126, 111, 23);
		getContentPane().add(btnNewButton);

		JLayeredPane panel = new JLayeredPane();
		panel.setToolTipText("");
		panel.setBorder(new LineBorder(new Color(0, 0, 0), 2));
		panel.setBounds(27, 102, 394, 244);
		getContentPane().add(panel);
		panel.setLayout(null);
		
		
		JLabel label = new JLabel("\u05E6\u05E4\u05D9\u05D9\u05D4 \u05D1\u05E0\u05EA\u05D5\u05E0\u05D9\u05DD \u05E1\u05D8\u05D8\u05D9\u05E1\u05D8\u05D9\u05D9\u05DD \u05E2\u05D1\u05D5\u05E8 \u05D4\u05DE\u05DC\u05D8\u05D4 \u05DE\u05E1\u05D5\u05D9\u05D9\u05DE\u05EA");
		label.setHorizontalAlignment(SwingConstants.RIGHT);
		label.setFont(new Font("David", Font.PLAIN, 15));
		label.setBounds(10, 39, 374, 20);
		panel.add(label);
		
		JButton button_3 = new JButton("\u05D4\u05E6\u05D2");
		button_3.setFont(new Font("David", Font.PLAIN, 14));
		button_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			    ShowStatisticsReport1 show1;
			    ArrayList<StatisticsbyAgeAndBirth> testList = new ArrayList<StatisticsbyAgeAndBirth>();
				try {
	
						testList=Control.Sys.getInstance().ShowStatisticsReportByBrith(Integer.parseInt(comboBox.getSelectedItem().toString()));
				} catch (Exception e1) {
					JOptionPane.showMessageDialog(null, "StatisticalReportByBirth Exception", "StatisticalReportByBirth Error", JOptionPane.ERROR_MESSAGE);
				}
				
					

					try 
					{
						
					
							show1=new ShowStatisticsReport1(testList);
							show1.setVisible(true);
							dispose();
					
					} 
					catch (HeadlessException e1)
					{
						JOptionPane.showMessageDialog(null, "StatisticalReportByBirth Exception", "StatisticalReportByBirth Error", JOptionPane.ERROR_MESSAGE);
					}
					catch (Exception e1) 
					{
						JOptionPane.showMessageDialog(null, "StatisticalReportByBirth Exception", "StatisticalReportByBirth Error", JOptionPane.ERROR_MESSAGE);
					}
				
			}
			
		});
		button_3.setBounds(91, 163, 73, 23);
		panel.add(button_3);
		
		JLabel label_1 = new JLabel("\u05D1\u05D7\u05E8 \u05DE\u05E1\u05E4\u05E8 \u05D4\u05DE\u05DC\u05D8\u05D4:");
		label_1.setHorizontalAlignment(SwingConstants.RIGHT);
		label_1.setFont(new Font("David", Font.PLAIN, 14));
		label_1.setBounds(198, 110, 100, 17);
		panel.add(label_1);
		
	
		
		JButton button_4 = new JButton("\u05D9\u05E6\u05D9\u05D0\u05D4 \u05DE\u05D4\u05DE\u05E2\u05E8\u05DB\u05EA");
		button_4.setFont(new Font("David", Font.PLAIN, 14));
		button_4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});
		button_4.setBounds(27, 379, 128, 23);
		getContentPane().add(button_4);
		
		ImageIcon ic=new ImageIcon("C:/Project/IDF1/MiscFiles/okets.jpg");
		JLabel lblNewLabel_1 = new JLabel(new ImageIcon("C:/Project/IDF1/MiscFiles/Picture4.jpg"));
		lblNewLabel_1.setBounds(-13, -84, 612, 610);
		getContentPane().add(lblNewLabel_1);
		
		ImageIcon ic1=new ImageIcon("C:/Project/IDF1/MiscFiles/okets.jpg");
		JLabel lblNewLabel_2 = new JLabel(new ImageIcon("C:/Project/IDF1/MiscFiles/Picture4.jpg"));
		lblNewLabel_2.setBounds(0, 0, 411, 374);
		panel.add(lblNewLabel_2);
		
		comboBox = new JComboBox();
		comboBox.setBounds(75, 108, 113, 20);
		panel.add(comboBox);
		panel.setLayer(comboBox, 1);
		 java.util.Vector<ArrayList<StatisticsbyAgeAndBirth>>birth=Sys.getInstance().BirthDetail();
		for (int i=0;i<birth.size();i++)
		{
			comboBox.addItem(birth.get(i).get(0).getBirthNum());
		}
		
		

		
	
	}


}
